package com.yager.config;

/**
 * @author 12866
 * @version 1.0
 * @date 2021/11/21 18:29
 */

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class IndexConfig implements CommandLineRunner {

//    @Override
//    public void run(String... args) throws Exception {
//        System.out.println("应用已经准备就绪 ... 启动浏览器并自动加载指定的页面 ... ");
//        try {
//            Runtime.getRuntime().exec("cmd   /c   start   http://127.0.0.1:8080/test");//指定自己项目的路径
//        } catch (Exception ex) {
//            ex.printStackTrace();
//        }
//    }
    @Value("${openProject.isOpen}")
    private boolean isOpen;

    @Value("${openProject.web.openUrl}")
    private String openUrl;

    @Value("${openProject.cmd}")
    private String cmd;

    @Override
    public void run(String... args){
        if(isOpen){
            String runCmd = cmd + " " + openUrl ;
            System.out.println("应用准备就绪，启动浏览器并运行命令: " + runCmd);
            try {
                Runtime.getRuntime().exec(runCmd);
                System.out.println("启动浏览器自动打开项目成功！！！");
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("启动项目自动打开浏览器失败！！！");
            }
        }
    }

}

